class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        stack=[]
        operators={
            '+':1,
            '-':1,
            '*':1,
            '/':1
        }
        for i in tokens:
            if i not in operators:
                stack.append(int(i))
            else:
                x=stack.pop()
                y=stack.pop()
                if i=="+":
                    stack.append(x+y)
                elif i=='-':
                    stack.append(y-x)
                elif i=="*":
                    stack.append(x*y)
                else:
                    if x*y<0:
                        stack.append(-(abs(y)//abs(x)))
                    else:
                        stack.append(y//x)
        return stack[0]


# 执行用时：
# 36 ms
# , 在所有 Python3 提交中击败了
# 98.10%
# 的用户
# 内存消耗：
# 16.2 MB
# , 在所有 Python3 提交中击败了
# 13.63%
# 的用户


class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        def add(a,b):
            return a+b
        def sub(a,b):
            return b-a
        def mult(a,b):
            return a*b
        def div(a,b):
            if a*b<0:
                return -(abs(b)//abs(a))
            else:
                return b//a
        stack=[]
        operators={
            '+':add,
            '-':sub,
            '*':mult,
            '/':div
        }
        for i in tokens:
            if i not in operators:
                stack.append(int(i))
            else:
                stack.append(operators[i](stack.pop(),stack.pop()))
        return stack[0]